<template>
	<view>
		<view class="scroll_box">
			<swiper v-if="list.length>4" class="swiper" circular="true" vertical="true" display-multiple-items="4" :autoplay="autoplay"
				:interval="interval" :duration="duration">
				<swiper-item v-for="(item,index) in list" :key="index">
					<view class="swiper-item">
						<view class="line1 flex flex-row justifity-center items-center">
							<image v-if="item.avatar&&item.avatar!=''"  :src="item.avatar" mode="aspectFit"></image>
							<image v-else src="https://tcjyh2022.oss-cn-hangzhou.aliyuncs.com/wechat/csqx_zhong.png" mode="aspectFit"></image>
							<view class="flex flex-col justifity-start items-start">
								<text class="c_52 f_28">{{item.nickname}}{{formatNumber(item.userPhone)}}</text>
								<text class="c_9 f_22">{{item.updateTime}}</text>
							</view>


						</view>
						<view class="line2">
							<text>抽到</text>
							<text class="line2-amount">{{item.money?'红包:'+item.money+'元':item.prizeDescription}}</text>
						</view>
					</view>
				</swiper-item>
			</swiper>
			<view v-else  class="swiper" style="height: auto;">
				<view v-for="(item,index) in list" :key="index">
					<view class="swiper-item">
						<view class="line1 flex flex-row justifity-center items-center">
							<image v-if="item.avatar&&item.avatar!=''"  :src="item.avatar" mode="aspectFit"></image>
							<image v-else src="https://tcjyh2022.oss-cn-hangzhou.aliyuncs.com/wechat/csqx_zhong.png" mode="aspectFit"></image>
							<view class="flex flex-col justifity-start items-start">
								<text class="c_52 f_28">{{item.nickname}}{{formatNumber(item.userPhone)}}</text>
								<text class="c_9 f_22">{{item.updateTime}}</text>
							</view>


						</view>
						<view class="line2">
							<text>抽到</text>
							<text class="line2-amount">{{item.money?'红包:'+item.money+'元':item.prizeDescription}}</text>
						</view>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>
<script>
	export default {
		name: '',
		props: {
			autoplay: {
				type: Boolean,
				default: true
			},
			interval: {
				type: Number,
				default: 1000
			},
			multiple:{
				type: Number,
				default: 4
			},
			duration: {
				type: Number,
				default: 1000
			},
			datalist: {
				type: Array,
				default: []
			},
		},
		data() {
			return {
				list: [],
			}
		},
		watch: {
			datalist: {
				immediate: true,
				handler(val) {
					this.list = val
				}
			}
		},
		methods:{
			formatNumber(number) {
			  let str = number.toString();
			
			  // 使用正则表达式匹配三位整数并替换为三个星号
			  return str.replace(/(\d{3})\d*(\d{4})/, "$1****$2");
			},
		}
	}
</script>

<style scoped lang="scss">
	.scroll_box {
		background: #FFFFFF;
		border-radius: 10rpx;

		.swiper {
			height: 400rpx;
		}
	}

	.swiper-item::after {
		content: '';
		clear: both;
	}

	.swiper-item {
		overflow: auto;
		padding: 20rpx 0;
		border-bottom: 1rpx solid #f7f7f7;

		image{
			width: 60rpx;
			height:60rpx;
			border-radius:50%;
			margin-right: 10rpx;
		}
	}

	.swiper-item .line1 {
		float: left;
	}

	.swiper-item .line2 {
		float: right;
		font-size: 24rpx;
	}

	.swiper-item .line2 .line2-amount {
		color: #DF4B43;
		font-size: 24rpx;
	}
</style>
